package com.alcohol.auth.server.support.grant.base;

import lombok.Getter;
import org.springframework.lang.Nullable;
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.core.AuthorizationGrantType;
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationGrantAuthenticationToken;
import org.springframework.util.Assert;

import java.util.Map;
import java.util.Set;

/**
 * 基础认证令牌抽象类
 * @author LiXinYu
 * @date 2025/11/8
 */
public abstract class BaseAuthenticationToken extends OAuth2AuthorizationGrantAuthenticationToken {

    /* 认证范围 */
    @Getter
    private final Set<String> scopes;

    /**
     * OAuth2-Base认证对象
     * @param authorizationGrantType    OAuth2授权类型
     * @param clientPrincipal   客户端认证信息
     * @param scopes    认证作用域
     * @param additionalParameters  扩展信息
     */
    public BaseAuthenticationToken(AuthorizationGrantType authorizationGrantType, Authentication clientPrincipal,
                                   @Nullable Set<String> scopes, @Nullable Map<String, Object> additionalParameters) {
        super(authorizationGrantType, clientPrincipal, additionalParameters);

        Assert.notNull(scopes, "scopes cannot be null！");
        this.scopes = Set.copyOf(scopes);
    }
}
